<?php
define('PLUGINFRAME', true);





define('APP_PATH', rtrim(getcwd(),'/').'/');
define('APP',basename(APP_PATH));
define('APP_LIB', APP_PATH.'libs/');
//define('TPL_PATH', DDGIVE.'/template');
//define('MODEL_PATH', DDGIVE.'/model');
//define('PUBLIC', DDGIVE.'/public');
define('CACHE_SERVER', 'memcached');
define('CACHE_MEMCACHED', '127.0.0.1:11211');


$mod=isset($_GET['m'])?$_GET['m']:'index';
$act=isset($_GET['a'])?$_GET['a']:'index';
define('MOD', strtolower($mod));
define('ACT', strtolower($act));

define('tpl', APP_PATH.'template/');
define('runtime', APP_PATH.'runtime/');
define('model_path', APP_PATH.'model/');

$lang=include APP_PATH.'lang/zh-cn.php';
$cfg=include APP_PATH.'config.inc.php';

require APP_PATH.'functions/functions.php';
require APP_PATH.'model/common.model.php';
require APP_PATH.'module/common.class.php';

set_exception_handler('exception_handler');
$filemodule=APP_PATH.'module/'.$mod.'.class.php';
if (file_exists($filemodule)){
   require $filemodule;
   $app=new $mod();
   if (method_exists($app, $act))
     $app->$act();
   else
     throw new Exception($lang['METHOD_NOT_EXIST']);
}else {
   throw new Exception($lang['FILE_NOT_EXIST']);   
}



function import(){
    $c=func_get_args();
    if (empty($c))
        return;
    return array_walk($c, create_function('$item,$key', 'include_once(APP_PATH.\'libs/\'.$item.\'.class.php\');'));
}


class Object{
    protected $_errors=array();
    protected $_errornum='';
    
    public function __construct(){
        $this->Object(implode(',', func_get_args()));
    }
    
    public function Object(){
        $this->_initialize(implode(',', func_get_args()));
    }
    
    public function _error($msg,$obj=''){
        if (is_array($msg)){
            $this->_errors=array_merge($this->_errors,$msg);
            $this->_errors+=count($msg);
        }else {
            $this->_errors[]=compact('msg','obj');
            $this->_errornum++;
        }
    }
    
    public function get_error(){
        return $this->_errors;
    }
    
    public function has_error(){
        return $this->_errornum;
    }
}






